package gtkwire.widget;

import gtkwire.*;

/**
*A widget used to choose from a list of items.
*/
public class GtkComboBox extends GtkBin
{
	public GtkComboBox()
	{
		super();
		this.widgetType = WT_GtkComboBox;
		gtkCreate();
	}

	public GtkComboBox( String name, GladeKey key )
	{
		super( name, key );
		this.widgetType = WT_GtkComboBox;
	}
	
	/**
	*Sets item in index active.
	*/
	public void setActiveIndex( int index )
	{
		app().sendCommand( name, GTKWireCommand.SET_ACTIVE_INDEX, index );
	}

	/**
	*Returns the index of the currently active item, or -1 if there's no active item.
	*/
	public int getActiveIndex()
	{
		GTKWireMessage answer = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.GET_INDEX, null );
		return ((Integer) answer.getMessageObject()).intValue();
	}

	/**
	*Returns the text in active option or null index.
	*/
	public String getActiveText()
	{
		GTKWireMessage answer = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.GET_ACTIVE, null );
		if( answer.getMessageType() == GTKWireMessage.M_NULL ) return null;
		return (String) answer.getMessageObject();
	}

	/**
	*Sets selectable text options.
	*/
	public void setItems( String[] items )
	{
		app().sendCommand( name, GTKWireCommand.SET_ITEMS, items );
		setActiveIndex( 0 );
	}

	/**
	*Sets whether the combo box will grab focus when it is clicked with the mouse.
	*/
	public void setFocusOnClick( boolean val )
	{
		app().sendCommand( name, GTKWireCommand.SET_FOCUS_ON_CLICK );
	}

	/**
	*Appends string option to the list of strings stored in combo_box.
	*/
	public void appendItem( String item )
	{
		app().sendCommand( name, GTKWireCommand.APPEND, item );
	}

	/**
	*Inserts string option at position 
	*/
	public void insertItem( String item, int position )
	{
		String[] msg = new String[2];
		msg[ 0 ] = item;
		msg[ 1 ] = ( new Integer( position )).toString();
		app().sendCommand( name, GTKWireCommand.INSERT, msg );
	}

	/**
	*Appends string option to the list of strings stored in combo_box.
	*/
	public void prependItem( String item )
	{
		app().sendCommand( name, GTKWireCommand.PREPEND, item );
	}

	/**
	*Removes the string option at position.
	*/
	public void removeItem( int position )
	{
		app().sendCommand( name, GTKWireCommand.REMOVE_ITEM, position );
	}

}//end class
